import config from '../../config'

export default new (class Snake {
  snake: HTMLElement
  header: HTMLDivElement
  bodies: Array<HTMLDivElement> = []

  constructor() {
    this.snake = document.querySelector("#snake")!
    this.header = document.querySelector("#header")!
    this.header.style.width = this.header.style.height = config.snake.model + "px"
    this.bodies.push(this.header)
  }

  // 设置蛇的样式
  setSnakeStyle(body: HTMLDivElement, position: { x: number, y : number}) {
    // 存储身体
    this.bodies.push(body)
    // 设置大小
    body.style.width = body.style.height = config.snake.model + "px"
    // 设置位置
    body.style.top = position.y + 'px'
    body.style.left = position.x + 'px'
    // 添加到身体
    this.snake.insertAdjacentElement('beforeend', body)
  }

})
